﻿@page "/Base_Manage/Base_Department/List"

@inherits BaseListWithEdit<Base_DepartmentTree, EditForm>

<Space Size="@("small")">

    @if (Operator.HasPerm("Base_Department.Add"))
    {
        <SpaceItem>
            <Button Type="@ButtonType.Primary" Icon="plus" OnClick="()=>Edit()">新建</Button>
        </SpaceItem>
    }
    @if (Operator.HasPerm("Base_Department.Delete"))
    {
        <SpaceItem>
            <Popconfirm Title="确认删除选中项吗?"
                    OnConfirm="()=>Delete()"
                    OnCancel="()=>{}"
                    OkText="确定"
                    CancelText="取消"
                    Disabled=@NoneSelectedItems>
                <Button Type="@ButtonType.Primary" Danger Icon="minus" Disabled=@NoneSelectedItems>删除</Button>
            </Popconfirm>
        </SpaceItem>
    }
    <SpaceItem>
        <Search Placeholder="关键字" EnterButton="true" @bind-Value="@KeyWord" OnSearch="()=>Refresh()" />
    </SpaceItem>
</Space>

<Table @ref="_table"
       TItem="Base_DepartmentTree"
       DataSource="Data"
       EnableVirtualization
       TreeChildren="item=>item.Children"
       DefaultExpandAllRows
       Loading="Loading"
       HidePagination
       PageSize="Pagination.PageRows"
       @bind-SelectedRows="SelectedItems"
       ScrollX="400"
       ScrollBarWidth="12px"
       Size="TableSize.Small"
       RowClassName="@(x => x.RowIndex % 2 == 0 ?"gray-2":"")">
    <ChildContent>
        <Selection Key="@(context.Id)" />
        <AntDesign.Column Title="部门名" DataIndex="Text" TData="string" />
        <ActionColumn Title="Action">
            <Space Size=@("small")>
                <SpaceItem>
                    <Button Type="@ButtonType.Link" Style="padding:0px" OnClick="()=>Edit(context)">Edit</Button>
                    <Popconfirm Title="确认删除吗?"
                                OnConfirm="()=>Delete(context.Id)"
                                OnCancel="()=>{}"
                                OkText="确定"
                                CancelText="取消">
                        <Button Danger Type="@ButtonType.Link" Style="padding:0px">Delete</Button>
                    </Popconfirm>
                </SpaceItem>
            </Space>
        </ActionColumn>
    </ChildContent>
</Table>

<style>
    .gray-2 {
        background-color: #fafafa;
    }
</style>

@code
{
    public List()
    {
        Area = "Base_Manage";
        GetDataList = "GetTreeDataList";
        Condition = "Name";
        NewTitle = "新建部门";
        EditTitle = "编辑部门";
        Pagination.PageRows = Int32.MaxValue;
    }
}